home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / clonecd / September 93.img / Archives / Utilities / Quicktime / SLINK's VCR QuickTime / MP Source / myQuickTime.c < prev    next >
Text File  |  1992-06-15  |  9KB  |  372 lines

  1. /*---------------------------------------------------------------------
  2.     File: myQuickTime.c
  3.     Purpose: Contains stuff to manage quicktime stuff such as openning
  4.     files, setting rates, and such.
  5.     
  6.     Created by: Geoffrey Slinker
  7.     Date: 10:58:03 AM  6/13/92
  8.     Modified: 
  9. ---------------------------------------------------------------------*/
  10. #include <GestaltEqu.h>
  11. #include <Movies.h>
  12. #include <MoviesFormat.h>
  13. #include <FixMath.h>
  14.  
  15. #include <oops.h>
  16.  
  17. #include "myQuickTime.h"
  18. #include "Alert_Class.h"
  19. #include "Dlog.h"
  20. #include "vcr.h"
  21.  
  22. extern Alert_Class *myAlert;
  23. extern VCR *vcr;
  24.  
  25.  
  26. /*...................................................................*/
  27. void QT::QT()
  28. {
  29.     movieWindow = NULL;
  30.     moviePosterWindow = NULL;
  31.     myMovie = NULL;
  32. }
  33. /*...................................................................*/
  34. void QT::~QT()
  35. {
  36.     CWindowPtr movieWindow,moviePosterWindow;
  37.     Movie myMovie;
  38.     
  39.     movieWindow = (*this).movieWindow;
  40.     moviePosterWindow = (*this).moviePosterWindow;
  41.     myMovie = (*this).myMovie;
  42.     
  43.     
  44.     if (movieWindow != NULL) {
  45.         DisposeWindow((WindowPtr)movieWindow);
  46.     }
  47.     
  48.     if (moviePosterWindow != NULL) {
  49.         DisposeWindow(moviePosterWindow);
  50.     }
  51.     
  52.     
  53.     if (myMovie != NULL) {
  54.         DisposeMovie(myMovie);
  55.     }
  56.     (*this).movieWindow = movieWindow;
  57.     (*this).moviePosterWindow = moviePosterWindow;
  58.     (*this).myMovie = myMovie;
  59. }
  60. /*...................................................................*/
  61. void QT::MovieCheck()
  62. {
  63.     long    version;
  64.     
  65.     
  66.     if (Gestalt( gestaltQuickTime, &version ) != noErr){
  67.         (*myAlert).AlertStop("\pFatal Error!",
  68.                                 "\pQuickTime not installed",
  69.                                 "\pPlease Install QuickTime",
  70.                                 "\pSorry.");
  71.     }
  72.     
  73.     if(EnterMovies() != noErr)    {
  74.         (*myAlert).AlertStop("\pFatal Error!",
  75.                                 "\pUnable to Enter Movies",
  76.                                 "\p",
  77.                                 "\pSorry.");
  78.     }
  79. }
  80. /*...................................................................*/
  81. void QT::LoadResources()
  82. {
  83.     CWindowPtr movieWindow, moviePosterWindow;
  84.     
  85.     movieWindow = (CWindowPtr)GetNewCWindow(MOVIE_WIND,(Ptr)0L,(CWindowPtr)(-1L));
  86.     if (movieWindow == NULL) {
  87.         SysBeep(7);
  88.         (*myAlert).AlertStop("\pFatal Error",
  89.                             "\pUnable to allocate new color window",
  90.                             "\pQT::LoadResources",NULL);
  91.     }
  92.     
  93.     moviePosterWindow = (CWindowPtr)GetNewCWindow(MOVIE_POSTER_WIND,(Ptr)0L,(CWindowPtr)(-1L));
  94.     if (moviePosterWindow == NULL) {
  95.         SysBeep(7);
  96.         (*myAlert).AlertStop("\pFatal Error",
  97.                             "\pUnable to allocate new color window",
  98.                             "\pQT::LoadResources",NULL);
  99.     }
  100.     
  101.     (*this).origBounds = (*movieWindow).portRect;
  102.     (*this).movieWindow = movieWindow;
  103.     (*this).moviePosterWindow = moviePosterWindow;
  104. }
  105. /*...................................................................*/
  106. int QT::OpenMovie()
  107. {    
  108.     PicHandle poster;
  109.     Movie myMovie;
  110.     CWindowPtr movieWindow,moviePosterWindow;
  111.     StandardFileReply        sfr;
  112.     SFTypeList    types =    {'MooV'};
  113.     short    resRefNum;
  114.     short numTypes = 1;
  115.     int w,h;
  116.     
  117.     // Shadow variables because the class are handles
  118.     // and therefore purgeable.
  119.     
  120.     myMovie = (*this).myMovie;
  121.     movieWindow = (*this).movieWindow;
  122.     moviePosterWindow = (*this).moviePosterWindow;
  123.     
  124.     
  125.     StandardGetFilePreview(0, numTypes, types, &sfr);
  126.     if (!sfr.sfGood) return(0);                /* Return if no selection */
  127.     
  128.     if (OpenMovieFile(&(sfr.sfFile), &resRefNum, 0) != noErr) {
  129.         return(0);
  130.     }
  131.     
  132.     SetWTitle(movieWindow,sfr.sfFile.name);
  133.     
  134.     if (NewMovieFromFile( &myMovie,resRefNum, nil, nil,0, nil ) != noErr) {
  135.         SysBeep(7);
  136.         (*myAlert).AlertStop("\pFatal Error",
  137.                             "\pUnable to get NewMovieFromFile",
  138.                             "\pQT::OpenMovie",NULL);
  139.     }
  140.     if (CloseMovieFile( resRefNum ) != noErr) {
  141.         SysBeep(7);
  142.         (*myAlert).AlertStop("\pFatal Error",
  143.                             "\pUnable to get CloseMovieFile",
  144.                             "\pQT::OpenMovie",NULL);
  145.     }    
  146.                                     
  147.     /* Get movie box and place movie at 0,0 */
  148.     GetMovieBox( myMovie, &dispBounds);
  149.     OffsetRect(&dispBounds,-dispBounds.left,-dispBounds.top);
  150.     SetMovieBox(myMovie, &dispBounds);        
  151.  
  152.     SetPort(movieWindow);
  153.     SetMovieGWorld(myMovie,nil,nil);
  154.     
  155.     GoToBeginningOfMovie(myMovie);
  156.     PrerollMovie(myMovie,0,0);                
  157.     SetMovieActive(myMovie,true);
  158.     
  159.     w = dispBounds.right - dispBounds.left;
  160.     h = dispBounds.bottom - dispBounds.top;
  161.     
  162.     SizeWindow( (WindowPtr)movieWindow,w,h,true);
  163.     SizeWindow( (WindowPtr)moviePosterWindow,w,h,true);
  164.     
  165.     poster = GetMoviePosterPict( myMovie );
  166.  
  167.         if (poster != nil)
  168.         {
  169.             GrafPtr oldPort;
  170.             Rect rect;
  171.             
  172.             GetPort(&oldPort);
  173.             SetPort(moviePosterWindow);
  174.             rect = (*moviePosterWindow).portRect;
  175.                     
  176.             DrawPicture( poster, &rect );
  177.             KillPicture( poster );
  178.             
  179.             SetPort(oldPort);
  180.         }
  181.     
  182.     (*this).myMovie = myMovie;
  183.     return(1);
  184.  
  185. }
  186. /*...................................................................*/
  187. void QT::PlayMovie()
  188. {
  189.     Movie myMovie;
  190.     CWindowPtr movieWindow;
  191.     
  192.     myMovie = (*this).myMovie;
  193.     movieWindow = (*this).movieWindow;
  194.     
  195.     
  196.     StartMovie(myMovie);                    
  197.  
  198.  
  199. }
  200. /*...................................................................*/
  201. void QT::CloseMovie()
  202. {
  203.     Movie myMovie;
  204.     int w,h;
  205.     CWindowPtr movieWindow, moviePosterWindow;
  206.     GrafPtr oldPort;
  207.     Rect origBounds;
  208.     
  209.     GetPort(&oldPort);
  210.     myMovie = (*this).myMovie;
  211.     
  212.     if (myMovie != NULL) {
  213.         DisposeMovie(myMovie);
  214.     }
  215.     myMovie = 0;  // This has to be here, apparently DisposeMovie didn't set
  216.                   // the myMovie variable to NULL
  217.     (*this).myMovie = myMovie;
  218.     
  219.     movieWindow = (*this).movieWindow;
  220.     moviePosterWindow = (*this).moviePosterWindow;
  221.     origBounds = (*this).origBounds;
  222.     
  223.     
  224.     w = origBounds.right - origBounds.left;
  225.     h = origBounds.bottom - origBounds.top;
  226.     
  227.     SizeWindow( (WindowPtr)movieWindow,w,h,true);
  228.     SizeWindow( (WindowPtr)moviePosterWindow,w,h,true);
  229.     
  230.     SetPort(movieWindow);
  231.     SetWTitle(movieWindow, "\pMovie Window");
  232.     EraseRect(&origBounds);
  233.     
  234.     SetPort(moviePosterWindow);
  235.     EraseRect(&origBounds);
  236.     
  237.     SetPort(oldPort);
  238.     
  239.     (*this).movieWindow = movieWindow;
  240.     (*this).moviePosterWindow = moviePosterWindow;
  241.     
  242.     (*vcr).ClearAllButtons();
  243.     
  244. }
  245. /*...................................................................*/
  246. void QT::MyMoviesTask(void)
  247. {    
  248.     Movie myMovie;
  249.     
  250.     myMovie = (*this).myMovie;
  251.     if (myMovie)
  252.     {
  253.         
  254.         MoviesTask(myMovie,0);
  255.         if (IsMovieDone(myMovie))    // Have we reached the end yet?        
  256.         {    
  257.             if ( (*vcr).vcr_mode == playing) {
  258.                 GoToBeginningOfMovie( myMovie );
  259.             }
  260.             else {
  261.                 (*vcr).ClearAllButtons();
  262.                 //(*vcr).RedrawButtons();
  263.                 //GoToBeginningOfMovie( myMovie );
  264.             }
  265.         }
  266.     }
  267. }
  268. /*...................................................................*/
  269. void QT::StopMyMovie(void)
  270. {
  271.     Movie myMovie;
  272.     
  273.     myMovie = (*this).myMovie;
  274.     
  275.     if(myMovie != NULL) {
  276.         StopMovie( myMovie );
  277.     }
  278.     (*this).myMovie = myMovie;
  279. }
  280. /*...................................................................*/
  281. void QT::FFMyMovie(void)
  282. {
  283.     Movie myMovie;
  284.     
  285.     myMovie = (*this).myMovie;
  286.     if (myMovie != NULL) {
  287.         SetMovieRate( myMovie, Long2Fix( 2L ) );
  288.     }
  289.     
  290.     (*this).myMovie = myMovie;
  291. }
  292. /*...................................................................*/
  293. void QT::RWMyMovie(void)
  294. {    
  295.     Movie myMovie;
  296.     
  297.     myMovie = (*this).myMovie;
  298.     if (myMovie != NULL) {
  299.         SetMovieRate( myMovie, Long2Fix( -2L) );
  300.     }
  301.     
  302.     (*this).myMovie = myMovie;
  303. }
  304. /*...................................................................*/        
  305. void QT::GoStartMyMovie(void)
  306. {
  307.     Movie myMovie;
  308.     
  309.     myMovie = (*this).myMovie;
  310.     if (myMovie != NULL) {
  311.         StopMovie(myMovie);
  312.         GoToBeginningOfMovie(myMovie);
  313.     }
  314.     
  315.     (*this).myMovie = myMovie;
  316. }
  317. /*...................................................................*/
  318. void QT::GoEndMyMovie(void)
  319. {
  320.     Movie myMovie;
  321.     
  322.     myMovie = (*this).myMovie;
  323.     if (myMovie != NULL) {
  324.         StopMovie(myMovie);
  325.         GoToEndOfMovie(myMovie);
  326.     }
  327.     
  328.     (*this).myMovie = myMovie;
  329.  
  330. }
  331. /*...................................................................*/
  332. void QT::RedrawPoster()
  333. {
  334.     PicHandle poster;
  335.     CWindowPtr moviePosterWindow;
  336.     GrafPtr oldPort;
  337.     Movie myMovie;
  338.     
  339.     GetPort(&oldPort);
  340.     
  341.     moviePosterWindow = (*this).moviePosterWindow;
  342.     myMovie = (*this).myMovie;
  343.     
  344.     if (myMovie != NULL) {
  345.         poster = GetMoviePosterPict( myMovie );
  346.  
  347.         if (poster != nil)
  348.         {
  349.             GrafPtr oldPort;
  350.             Rect rect;
  351.             
  352.             GetPort(&oldPort);
  353.             SetPort(moviePosterWindow);
  354.             rect = (*moviePosterWindow).portRect;
  355.             
  356.             //SetWindowPic( (WindowPtr)moviePosterWindow,poster);
  357.             //InsetRect( &rect, 3, 3 );
  358.             
  359.             DrawPicture( poster, &rect );
  360.             KillPicture( poster );
  361.             
  362.             SetPort(oldPort);
  363.         }
  364.     }
  365.     SetPort(oldPort);
  366. }
  367. /*...................................................................*/
  368. /*...................................................................*/
  369. /*...................................................................*/
  370. /*...................................................................*/
  371. /*...................................................................*/
  372.